{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "++++复合圆形++++\n",
      "所有的孩子们 点(2,3)\n",
      "点(2,3)\n",
      "====end=====\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "from abc import abstractmethod ,ABCMeta\n",
    "\n",
    "class graphic(metaclass=ABCMeta):\n",
    "    @abstractmethod\n",
    "    def draw(self):\n",
    "        pass\n",
    "    @abstractmethod\n",
    "    def add(self,graphic):\n",
    "        pass\n",
    "    @abstractmethod\n",
    "    def getchildren(self,graphic):\n",
    "        pass\n",
    "    \n",
    "class point(graphic):\n",
    "    def __init__(self,x,y):\n",
    "        self.x=x\n",
    "        self.y=y\n",
    "    def draw(self):\n",
    "        print(self)\n",
    "    def add(self,graphic):\n",
    "        raise TypeError\n",
    "    \n",
    "    def getchildren(self,graphic):\n",
    "        raise TypeError\n",
    "        \n",
    "    def __str__(self):\n",
    "        return '点(%s,%s)'%(self.x,self.y)\n",
    "class line(graphic):\n",
    "    def __init__(self,p1,p2):\n",
    "        self.p1=p1\n",
    "        self.p2=p2\n",
    "    def draw(self):\n",
    "        print(self)\n",
    "    def add(self,graphic):\n",
    "        raise TypeError\n",
    "    def getchildren(self):\n",
    "        raise TypeError\n",
    "    def __str__(self):\n",
    "        return \"线段[%s,%s]\"%(self.p1,self.p2)\n",
    "class picture(graphic):\n",
    "    def __init__(self):\n",
    "        self.children=[]\n",
    "    def add(self,graphic):\n",
    "        self.children.append(graphic)\n",
    "    def getchildren(self,graphic):\n",
    "        return self.children\n",
    "    def draw(self):\n",
    "        print('++++复合圆形++++')\n",
    "        for i in self.children:\n",
    "            print('所有的孩子们',i)\n",
    "            i.draw()\n",
    "        print('====end=====')\n",
    "        \n",
    "pi=picture()\n",
    "res=pi.add(point(2,3))\n",
    "print(pi.draw())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
